package com.vecspace.scheduler.job;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.vecspace.utils.log.HLogger;

public class JobProxy  implements Job {
	@Override
	public void execute(JobExecutionContext ctx) throws JobExecutionException {
		JobDataMap jobDataMap = ctx.getJobDetail().getJobDataMap();
		Object jobBean = jobDataMap.get("job_bean");
		boolean force = false;
		try{
			force = jobDataMap.getBoolean("job_excute_force");		
		}catch(Exception ex){
			
		}		
		if(jobBean instanceof AbstractJob){
			AbstractJob job = (AbstractJob)jobBean;
			if(!force && job.executing()){
				HLogger.DEFAULT().warn("上一次作业还未执行完(excuting() == true), 跳过本次作业。"+job.getClass().getName()+","+job.getJobName());
				return;
			}
			job.doExecute(null);
		}else{
			throw new JobExecutionException("没有指定要执行的job");
		}
	}
}
